﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using Microsoft.Reporting.WebForms;

namespace IDML.Web.Common
{
    public class ReportHelper
    {

        public ReportHelper()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public bool CreateReport(string StoreProcedureName, SqlParameter[] Parameter,
            ref  Microsoft.Reporting.WebForms.ReportViewer ReportViewer, string ReportDataSource)
        {
            bool reportbind = false;
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["IDMLConnection"].ConnectionString))
            {
                SqlCommand com = new SqlCommand();
                com.Connection = con;
                com.CommandType = CommandType.StoredProcedure;
                com.CommandText = StoreProcedureName;
                com.Parameters.AddRange(Parameter);
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(com);
                da.Fill(ds);
                ReportDataSource datasource = new ReportDataSource(ReportDataSource, ds.Tables[0]);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    ReportViewer.LocalReport.DataSources.Clear();
                    ReportViewer.LocalReport.DataSources.Add(datasource);
                    reportbind = true;
                }
            }
            return reportbind;
        }







    }
}